 <template>
  <transition name="loading">
    <div class="Loading">
      <div class="Loading-img" :style="{backgroundPositionY: -(positionY%7)*2.5 + 'rem'}"></div>
      <svg class="Loading-ellipse" xmlns="http://www.w3.org/2000/svg" version="1.1">
        <ellipse cx="26" cy="10" rx="26" ry="10" style="fill:#ddd;stroke:none;"></ellipse>
      </svg>
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {
      positionY: 0,
      timer: null
    };
  },
  mounted() {
    this.timer = setInterval(() => {
      this.positionY++;
    }, 600);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  }
};
</script>

<style lang="scss">
@import "../styles/mixin";
@keyframes load {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-50px);
  }
  100% {
    transform: translateY(0px);
  }
}
@keyframes ellipse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.3);
  }
  100% {
    transform: scale(1);
  }
}
.Loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  @include wh(2.5rem, 2.5rem);
}
.Loading-img {
  @include wh(100%, 100%);
  background: url(../assets/icon-loading.png) no-repeat 0 0;
  background-size: 2.5rem auto;
  transform: translateY(0px);
  animation: load 0.6s infinite ease-in-out;
  position: relative;
  z-index: 11;
}
.Loading-ellipse {
  position: absolute;
  @include wh(2.6rem, 2rem);
  top: 2.2rem;
  left: 0.2rem;
  z-index: 10;
  animation: ellipse 0.6s infinite ease-in-out;
}
.loading-enter-active,
.loading-leave-active {
  transition: opacity 1s;
}
.loading-enter,
.loading-leave-active {
  opacity: 0;
}
</style>
